﻿<UserControl x:Class="OIManager.Views.SetupCatalogView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:df="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm.Toolkit"
    xmlns:Micro="clr-namespace:Caliburn.Micro;assembly=Caliburn.Micro" 
    xmlns:Controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" mc:Ignorable="d">
    
    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="6" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        
        <!--MASTER LIST OF DATASETS-->
        <ListBox Name="Items" Grid.Column="0" Grid.Row="0" 
                 Height="550" Width="480" Margin="4" 
                 SelectedItem="{Binding Item, Mode=TwoWay}"
                 VerticalAlignment="Top">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Name}" Style="{StaticResource ListItems}" />
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        
        <!--DETAILS-->
        <df:DataForm x:Name="DetailsForm" Grid.Column="1" Grid.Row="0"
                     ItemsSource="{Binding Items}" AutoGenerateFields="False"
                     CurrentItem="{Binding Item, Mode=TwoWay}"
                     AutoEdit="False"
                     CommandButtonsVisibility="Edit,Cancel,Commit,Navigation"
                     DescriptionViewerPosition="BesideLabel"
                     VerticalAlignment="Top" HorizontalAlignment="Left" 
                     Height="550" Width="480" Margin="4">
            
            <df:DataForm.EditTemplate>
                <DataTemplate>
                    <StackPanel>
                        <df:DataField Label="Dataset Name">
                            <TextBox Text="{Binding Name, Mode=TwoWay, ValidatesOnDataErrors=true}" />
                        </df:DataField>

                        <df:DataField Label="Description">
                            <TextBox Text="{Binding Description, Mode=TwoWay}" TextWrapping="Wrap" Height="96"/>
                        </df:DataField>

                        <df:DataField Label="Categories">
                            <StackPanel Orientation="Horizontal">
                                <ComboBox Micro:Action.Target="SetupCatalogViewModel"
                                          SelectedValue="{Binding SelectedCategoryValue, Mode=TwoWay}"
                                          ItemsSource="{Binding CategoryItems}" 
                                          DisplayMemberPath="Name" SelectedValuePath="ID">
                                </ComboBox>
                                <Button Content="+" Width="24" Margin="4,0,0,0" Micro:Message.Attach="[Event Click]=[Action AddCategory()]"/>
                                <Button Content="-" Width="24" Margin="4,0,0,0" Micro:Message.Attach="[Event Click]=[Action RemCategory()]"/>
                            </StackPanel>
                        </df:DataField>

                        <df:DataField Label="Sources">
                            <StackPanel Orientation="Horizontal">
                                <ComboBox Micro:Action.Target="SetupCatalogViewModel"
                                      SelectedValue="{Binding SelectedSourceValue, Mode=TwoWay}"
                                      ItemsSource="{Binding SourceItems}" 
                                      DisplayMemberPath="Name" SelectedValuePath="ID">
                                </ComboBox>
                                <Button Content="+" Width="24" Margin="4,0,0,0" Micro:Message.Attach="[Event Click]=[Action AddSource()]"/>
                                <Button Content="-" Width="24" Margin="4,0,0,0" Micro:Message.Attach="[Event Click]=[Action RemSource()]"/>
                            </StackPanel>
                        </df:DataField>

                        <df:DataField Label="Table Name">
                            <TextBox Text="{Binding TableName, Mode=TwoWay, ValidatesOnDataErrors=true}" />
                        </df:DataField>

                        <df:DataField Label="Map Layer ID">
                            <TextBox Text="{Binding LayerID, Mode=TwoWay, ValidatesOnDataErrors=true}" />
                        </df:DataField>

                        <df:DataField Label="Tags">
                            <TextBox Text="{Binding Tags, Mode=TwoWay}"/>
                        </df:DataField>

                        <df:DataField Label="Contact Email">
                            <TextBox Text="{Binding ContactEmail, Mode=TwoWay}"/>
                        </df:DataField>

                        <df:DataField Label="Update Frequency">
                            <TextBox Text="{Binding UpdateFrequency, Mode=TwoWay}"/>
                        </df:DataField>

                        <df:DataField Label="Published Date">
                            <Controls:DatePicker SelectedDate="{Binding PublishedDate, Mode=TwoWay, ValidatesOnDataErrors=true}" />
                        </df:DataField>

                        <df:DataField Label="Is Published?">
                            <CheckBox IsChecked="{Binding IsPublished, Mode=TwoWay, ValidatesOnDataErrors=true}" />
                        </df:DataField>

                        <df:DataField Label="Is Dataset Spatial?">
                            <CheckBox IsChecked="{Binding IsSpatial, Mode=TwoWay, ValidatesOnDataErrors=true}" />
                        </df:DataField>

                    </StackPanel>
                </DataTemplate>
            </df:DataForm.EditTemplate>
        </df:DataForm>
        
        <!--SEP-->
        <Grid Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Background="#08000000" Margin="24,2,24,2"/>
        
        <!--BUTTONS-->
        <StackPanel Orientation="Horizontal" Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2" HorizontalAlignment="Left" Margin="4">
            <Button x:Name="AddDataset" Content="Add Dataset" Width="120" Margin="0,0,8,0" />
            <Button x:Name="RemDataset" Content="Remove Dataset" Width="120" Margin="0,0,8,0" />
        </StackPanel>

    </Grid>
</UserControl>
